/***********************************************************************
 * Module:  Filiere.java
 * Author:  Alexandro
 * Purpose: Defines the Class Filiere
 ***********************************************************************/

package dao;

import java.util.*;
import java.sql.*;

public class Filiere extends Codage implements InterfaceDAO {
   public Diplome[] diplome;
   
   public int nbEtudiants() {
      // TODO: implement
      return 0;
   }
   
   public int insert(int[] fk) {
      
      if (fk.length == 1)
      try {			
			dao.DAODataConnection.executer("INSERT INTO filiere VALUES("+getCode()+",null,'"+getLibelle()+"');");											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
   }
   
   public Object[] select(int[] param) {
      
      try {			
			
			ResultSet tabla = dao.DAODataConnection.executerQuery("SELECT * FROM filiere");								
			int max = dao.DAODataConnection.maxRows;
			Filiere[] sortie = new Filiere[max];
			int i=0;
			while(tabla.next() && i<max)	
			{
				Filiere neuf = new Filiere();
				neuf.setCode(tabla.getInt(1));
				neuf.setLibelle(tabla.getString(2));
				sortie[i]=neuf;
				i++;
			}		
			return sortie;			
			}
		catch(Exception e){ System.out.println(e); }		
		
		return null;
		
   }
   
   public int delete(int[] param) {
   	
      try {			
			dao.DAODataConnection.executer("DELETE FROM filiere WHERE code_fil="+getCode());											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
   }
   
   public int update(int[] fk) {      	      	
        try {			
        	if (fk == null)
			dao.DAODataConnection.executer("UPDATE filiere SET libelle='"+getLibelle()+"' where code_fil="+getCode());											
			else 
			dao.DAODataConnection.executer("UPDATE filiere SET code_dep="+fk[0]+" where code_fil="+getCode());											
			return 0;			
			}
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
   }

}